package com.dkts.oil.web.vo.response;

import java.util.HashMap;

import com.dkts.oil.constant.ExceptionEnum;
import com.dkts.oil.constant.ResultCode;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 返回结果类
 */
@Data
@Schema(description = "返回结果类")
public class Result<T> {
    @Schema(description = "状态码")
    private int code;
    @Schema(description = "消息")
    private String msg;
    @Schema(description = "数据对象")
    private T data;

    public Result() {
    }

    public Result(int code, String msg) {
         this.code = code;
         this.msg = msg;
    }

    public Result(int code, String msg, Object date) {
       this.code = code;
       this.msg = msg;
       this.data = (T) date;
    }


    public static Result success() {
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg());
    }

    public static Result success(String msg) {
        return new Result(ResultCode.SUCCESS.getCode(), msg);
    }

    public static Result success(Object date) {
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), date);
    }

    public static Result erro() {
        return new Result(ExceptionEnum.UNKNOWN_ERROR.getCode(), ExceptionEnum.UNKNOWN_ERROR.getMsg());
    }

    public static Result erro(String msg) {
        return new Result(ExceptionEnum.UNKNOWN_ERROR.getCode(), msg);
    }

    public static Result erro(int code, String msg) {
        return new Result(code, msg);
    }

    public static Result erro(int code, String msg, Object data) {
        return new Result(code, msg, data);
    }

    public static Result ywErro(String msg) {
        return new Result(ExceptionEnum.YW_ERROR.getCode(), msg);
    }

    public static Result PromissionErro(String msg) {
        return new Result(ExceptionEnum.PERMISSION_ERROR.getCode(), msg);
    }

    public static Result ywErro(int code, String msg) {
        return new Result(code, msg);
    }

    public static Result error(ResultCode resultCode) {
        return new Result(resultCode.getCode(), resultCode.getMsg());
    }

    public static Result errorMsg(String errMsg) {
        return new Result(ExceptionEnum.YW_ERROR.getCode(), errMsg);
    }

    public static Result paramError(String msg) {
        return new Result(ExceptionEnum.PARAM_ERROR.getCode(), msg);
    }

    public static Result fileTypeError(String msg) {
        return new Result(ExceptionEnum.FILE_TYPE_ERROR.getCode(), msg);
    }

    public static Result createError(String message) {
        return new Result(ExceptionEnum.UNKNOWN_ERROR.getCode(), message);
    }

    public static Result createError(int code, String message) {
        return new Result(code, message);
    }

    public static Result createError(ExceptionEnum exceptionEnum) {
        return new Result(exceptionEnum.getCode(), exceptionEnum.getMsg());
    }

    public static Result createError(ExceptionEnum exceptionEnum, Object data) {
        return new Result(exceptionEnum.getCode(), exceptionEnum.getMsg(), data);
    }
}
